
export class AppUser {
  public id:string;
  public name:string;
  public phoneNumber:string;
  public area:string;
  public roles:Array<string>

  public year:number
  public quarter:number
  public quarterEndDays:number

  public token:string;
}

// getApp().globalData
// debugger
export class GlobalDataConfig {
  public appUser:AppUser;
  public userInfo:wx.UserInfo;
  public authSetting:wx.AuthSetting

  public updateTask:any;

  public abilityAllList = [
    '销售能力',
    '策划能力',
    '市场研究',
    '管理能力',
    '资源整合',

    '团队人员管理',
    '团队文化锻造',
    '业务基础精进',
    '技术工艺创新',
    '外部资源整合',
    '内部资源协调'
  ];

  public get name () {
    return this.userInfo.nickName
  }

  public get taskgrade () {
    return '1星=不好，2星=一般，3星=及格，4星=良好，5星=优秀'
  }

  public get token () {
    return typeof this.appUser === 'undefined' ? '' : this.appUser.token
  }

  public get isDevelopment () {
    return process.env.VUE_APP_ENV === 'development'
  }

  public get userIsStudent () {
    return this.appUser.roles.indexOf('student') >= 0
  }

  public get userIsTeacher () {
    return this.appUser.roles.indexOf('teacher') >= 0
  }

  public get userIsAdmin () {
    return this.appUser.roles.indexOf('admin-area') >= 0 || this.appUser.roles.indexOf('admin-group') >= 0 || this.appUser.roles.indexOf('admin-super') >= 0
  }

  public orderlist = [
    4, // 待审核
    7, // 待复审
    1, // 学习中
    6, // 未打分
    2, // 已完成
    3, // 已过期
    5 // 未批准
  ]

  public orderByTasks (items) {
    var orderlist = this.orderlist
    items.sort(function (a, b) {
      if (a.status === b.status) {
        if (a.status === 1) {
          return new Date(a.deadLine).getTime() - new Date(b.deadLine).getTime()
        } else if (a.status === 2) {
          return new Date(a.completeTime).getTime() - new Date(b.completeTime).getTime()
        } else {
          return new Date(a.creationTime).getTime() - new Date(b.creationTime).getTime()
        }
      }
      return orderlist.indexOf(a.status) - orderlist.indexOf(b.status)
    })
  }
}

export default new GlobalDataConfig()
